package com.ayu.a.practice01;

import java.util.Arrays;

/**
 * @Author 徐林玉
 * @Description IntersectPrac
 * @Date 2022/11/8 17:03
 * @Version 1.0
 */
public class IntersectPrac {

    public static void main(String[] args) {


        int[] nums1 = new int[]{4,7,9,7,6,7};

        int[] nums2 = new int[]{5,0,0,6,1,6,2,2,4};

        int[] intersect = intersect(nums1, nums2);

        for (int i = 0; i < intersect.length; i++) {


            System.out.print(intersect[i] + "   ");
        }


    }

    public static int[] intersect(int[] nums1, int[] nums2) {




        int[] nums3 = new int[nums2.length];
        int[] bool1 = new int[nums2.length];

        int index = 0;

        for (int i = 0; i < nums1.length; i++) {

            int cur = nums1[i];

            for (int j = 0; j < nums2.length; j++) {

                if (cur == nums2[j] && bool1[j] != 1) {

                    nums3[index++] = cur;
                    bool1[j] = 1;
                    break;
                }
            }
        }

        nums3 = Arrays.copyOf(nums3,index);

        return nums3;

    }
}
